'''
Created on 2010/09/07

@author: yyonezawa
'''
class VirtualTag(object):
        
    __UNIQUE_ID = ""    
    __USER_MEMORY = list()
    __ACCESS_WIDTH = 2 #for byte
        
    def __init__(self, tag_id, access_width):
        self.__UNIQUE_ID = tag_id
        self.__ACCESS_WIDTH = access_width
        
    def updateUserMemory(self, start_address, write_data):
        #check User_Memory
        remain_address = (len(self.__USER_MEMORY) - (start_address + (len(write_data) / self.__ACCESS_WIDTH) )) * -1
        for index in range(remain_address):
            self.__USER_MEMORY.append("")
        
        #insert data to USER_MEMORY
        for index in range(len(write_data) / self.__ACCESS_WIDTH):
            self.__USER_MEMORY[start_address + index] = write_data[(index * self.__ACCESS_WIDTH):(index * self.__ACCESS_WIDTH) + self.__ACCESS_WIDTH]        
        
        print "USER_MEMORY++++++++"
        print self.__USER_MEMORY
        print "++++++++"
        
    def getUserMemory(self, start_address, width):
        
        if len(self.__USER_MEMORY) <= start_address + width:
            return ""
        
        return_value = ""        
        for index in range(width):
            return_value += self.__USER_MEMORY[start_address + index] 
        return return_value
    
    def getAllUserMemory(self):        
        return_value = ""
        for data in self.__USER_MEMORY:
            temp = data
            if data == "":
                temp = "X" * self.__ACCESS_WIDTH
            return_value += temp
        return return_value
        
    def clearUserMemory(self):
        self.__USER_MEMORY = ""
        return True
    
    def getAccessableMemory(self):
        return self.__ACCESS_WIDTH
    